﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// TableManager 的摘要说明
/// </summary>
/// 
using Global;
using BussinessLib;

public class TableManager:BaseManager
{
    DataTable m_DataTable;
    Table m_Table;
    Helper m_DataAccess;
    public TableManager()
    {
        //m_DataTable = new DataTable();
        m_Table = new Table();
        m_DataAccess = new Helper();
      
    }

    ///______________________
    ///

  //  bool BaseManager.DeleteObject(object obj)//删除餐位
    public bool DeleteObject(object obj)
    {
        Table table = (Table)obj;
        int iID = table.GetID();
        string strSql = "delete from Seat where T_nID  = " + iID;
        return m_DataAccess.ExecuteSql(strSql);
    }
    //bool BaseManager.AddObject(object obj)//增加餐位
    public bool AddObject(object obj)
    {
        Table table = (Table)obj;
        string strSql;


        int iAttributeID = table.GetAttributeID();
        int iResID = table.GetResID();
        int iSeatNum = table.GetSeatNum();
        float fAverageCost = table.GetAverageCost();
        strSql = "insert into  Seat(T_nResID,T_nSeatNum,T_fAverageCost,T_nAttributeID)values("
            + iResID + "," + iSeatNum + "," +
            fAverageCost + "," + iAttributeID + ")";


        // return strSql;
        return m_DataAccess.ExecuteSql(strSql);


    }
   // bool BaseManager.UpdateObject(object obj)//更新餐位
    public bool UpdateObject(object obj)
    {
        Table table = (Table)obj;
        int iID = table.GetID();
        float fAverageCost = table.GetAverageCost();
        int iSeatNum = table.GetSeatNum();
        int nResID = table.GetResID();
        int nAttributeID = table.GetAttributeID();

        string strSql = "update Seat set  T_nResID =   " + nResID + " ,T_nSeatNum =  "
            + iSeatNum
            + ",T_fAverageCost =  " + fAverageCost + ",T_nAttributeID = "
            + nAttributeID + " where T_nID =  " + iID;



        return m_DataAccess.ExecuteSql(strSql);
    }






    ///_______________________
    public DataTable SearchSeatInfo(int iResID)//根据餐馆id搜索餐位信息
    {
        string strSql;
        strSql = "select T_nID,T_nSeatNum,T_fAverageCost,TA_sName from Seat,TableAttribute where TA_nID = T_nAttributeID and T_nResID =  " + iResID;
        return m_DataAccess.ExecuteDataTable(strSql);
    }
    public int SearchSeatNum(int iAttriID, int iResId)//根据餐位位置id搜索餐位数目
    {
        string strSql;
        strSql = "select count(*)  from Seat where T_nAttributeID = " + iAttriID
            + "and T_nResID =" + iResId;
        m_DataTable = m_DataAccess.ExecuteDataTable(strSql);
        return int.Parse(m_DataTable.Rows[0][0].ToString());
    }
    public int SearchSeatAllNum(int iResID)//搜索餐位总数目
    {
        string strSql;
        strSql = "select count(*) from Seat where T_nResID = " + iResID;
        m_DataTable = m_DataAccess.ExecuteDataTable(strSql);
        return int.Parse(m_DataTable.Rows[0][0].ToString());
    }
    public DataTable SearchOrderTable(int iResID)//搜索被预定的餐位 
    {
        string strSql;
        strSql = "select ord_nTableNum , ord_dtArrivalTime , ord_dtBookTime from OrderRecord where  ord_nState = "
            + iResID;


        m_DataTable = m_DataAccess.ExecuteDataTable(strSql);

        return m_DataTable;

    }
    public DataTable SearchTable(int iResID)//某个餐馆被预订的餐位
    {


        string strSql;
        strSql = "select ord_nTableNum , ord_dtArrivalTime , ord_dtBookTime from OrderRecord where  ord_nState = "
            + iResID;


        m_DataTable = m_DataAccess.ExecuteDataTable(strSql);

        return m_DataTable;

    }

  }
